package com.atguigu.spzx.model.vo.base;

import lombok.Data;

// com.atguigu.spzx.model.vo.common
@Data
public class Result<T> {

    // 返回码
    private Integer code;

    // 返回消息
    private String message;

    // 返回数据
    private T data;

    // 私有化构造
    private Result() {}

    // 返回数据
    public static <T> Result<T> build(T body, Integer code, String message) {
        Result<T> result = new Result<>();
        result.setData(body);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> ok(T body) {
        return  build(body,200,"success");
    }

    public static <T> Result<T> ok() {
        return  build(null,200,"success");
    }


    public static <T> Result<T> fail(ResultCodeEnum resultCodeEnum) {
        return  build(null,resultCodeEnum.getCode(),resultCodeEnum.getMessage());
    }

    public static <T> Result<T> fail() {
        return  build(null,ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMessage());
    }

}